package cn.blackjuly.cadmin.controller;

import cn.blackjuly.cadmin.model.Setting;
import com.jfinal.core.Controller;

public class SettingController extends Controller {
    public void website() {
        setAttr("siteName", Setting.findValue("site_name"));
        setAttr("siteLogo", Setting.findValue("site_logo"));
        setAttr("siteQrcode", Setting.findValue("site_qrcode"));
        setAttr("siteUrl", Setting.findValue("site_url"));
        setAttr("siteIcp", Setting.findValue("site_icp"));
        setAttr("siteCopyright", Setting.findValue("site_copyright"));
        setAttr("siteOpen", Setting.findValue("site_open"));
        render("website.jsp");
    }

    public void editWebSite() {
        String siteName = getPara("siteName");
        String logo = getPara("logo");
        String qrcode = getPara("qrcode");
        String siteUrl = getPara("siteUrl");
        String icp = getPara("icp");
        String copyright = getPara("copyright");
        String siteStatus = getPara("siteStatus");

        Setting.updateValue("site_name", siteName);
        Setting.updateValue("site_logo", logo);
        Setting.updateValue("site_qrcode", qrcode);
        Setting.updateValue("site_url", siteUrl);
        Setting.updateValue("site_icp", icp);
        Setting.updateValue("site_copyright", copyright);
        Setting.updateValue("site_open", siteStatus);

        setAttr("success", true);
        setAttr("message", "更新成功");
        renderJson();
    }

    public void seo() {
        setAttr("title", Setting.findValue("title"));
        setAttr("keyword", Setting.findValue("keyword"));
        setAttr("description", Setting.findValue("description"));
        render("seo.jsp");
    }

    public void editSeo() {
        String title = getPara("title");
        String keyword = getPara("keyword");
        String description = getPara("description");

        Setting.updateValue("title", title);
        Setting.updateValue("keyword", keyword);
        Setting.updateValue("description", description);

        setAttr("success", true);
        setAttr("message", "更新成功");
        renderJson();
    }
}
